home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / dobbs / v17n05 / penchkbk.asc < prev    next >
Encoding:
Text File  |  1992-03-30  |  4.6 KB  |  113 lines

  1. _VISUAL BASIC AND WINDOWS 3.1_
  2. by Moshe Lichtman
  3.  
  4.  
  5. [LISTING ONE]
  6.  
  7. Type RcResult                   ' RcResult structure
  8.     SYGraph As syg              ' Symbol Graph element
  9.     wREsultsType As Integer     ' Status of RcResult handling 
  10.     cSyv As Integer                    
  11.     lpsyv As Long                      
  12.     hSyv As Integer                   
  13.     nBaseLine As Integer          
  14.     nMidLine As Integer              
  15.     hPenData As Integer               
  16.     rectboundink As RECTSHORT          
  17.     pntEnd As PointShort               
  18.     lprc As Long                      
  19. End Type 
  20.  
  21. Type syg                                ' Symbol Graph structure
  22.     rgpntHotSpotsArray As PointArray    ' "hot spot" array
  23.     cHotSpot As Integer                
  24.     nFirstBox As Integer              
  25.     lRecogVal As Long                 
  26.     lpSye As Long                       ' Pointer to first Symbol Element
  27.     cSye As Integer                     ' Number of Symbol elements
  28.     lpSyc As Long                     
  29.     csyc As Integer                   
  30. End Type                               
  31.  
  32. Type SYE                                ' Symbol element structure
  33.     Syv As Long                         ' Symbol Value
  34.     lRecogVal As Long                  
  35.     cl As Integer                       
  36.     iSyc As Integer                    
  37. End Type                                                              
  38.  
  39. 'The following two functions copy data to/from Visual Basic strings 
  40. 'and from/to memory pointed by long pointers.
  41. Declare Sub VBTypeToCPointer Lib "PENCNTRL.VBX" (lpSrc As Any, ByVal 
  42. lpDest As Long, ByVal cb As Integer)
  43. Declare Sub CPointerToVBType Lib "PENCNTRL.VBX" (ByVal lpSrc As Long, 
  44. lpDest As Any, ByVal cb As Integer)
  45.  
  46.  
  47.  
  48.  
  49. [LISTING TWO]
  50.  
  51. Sub Process_cGestures 
  52.     Dim VBrc As RcResult
  53.     Dim SyeTable() As SYE                ' array of Symbol elements
  54.     CPointerToVBType ByVal RcResult, VBrc, 80  'copy RcResult struct to VB var
  55.     NumOfSymbols% = VBrc.SYGraph.cSye    ' get number of Symbol elements
  56.     lpSye& = VBrc.SYGraph.lpSye          ' pointer to first Symbol Element
  57.     ReDim SyeTable(NumOfSymbols%)        ' re-define Symbol array
  58.                                          ' copy Symbol elements
  59.     CPointerToVBType ByVal lpSye&, SyeTable(0), NumOfSymbols% * 12    
  60.     If (NumOfSymbols% = 1) Then          ' process only if single gesture
  61.         Syv& = SyeTable(0).Syv
  62.         SyvType& = Syv& \ &H10000        ' get Symbol type. Is it a gesture?
  63.         If (SyvType& = SYVHI_GESTURE) Then ' if so, is it a circle-H gesture?
  64.              If (Syv& = (SYV_CIRCLELOA + Asc("h") - Asc("a"))) Then    
  65.                 HideCmd_Click            ' hide menu-bar
  66.                 VBrc.wREsultsType = VBrc.wREsultsType Or RCRT_ALREADYPROCESSED
  67.              End If                      ' mark to prevent further processing
  68.         End If
  69.         VBTypeToCPointer VBrc, ByVal RcResult, 80   ' update RcResult
  70.     End If
  71. End Sub
  72.  
  73.  
  74.  
  75. [LISTING THREE]
  76.  
  77. ' DuplicatePenData() takes a handle to ink (hPenData or hInk) and returns a 
  78. ' new hInk/hPenData that has a copy of the ink. NOTE: Whenever this function 
  79. ' is used, a GlobalFree() call must be issued to release the memory.
  80. Declare Function DuplicatePenData Lib "PENWIN" (ByVal hPenData As 
  81. Integer, ByVal gMemFlags As Integer) As Integer
  82.  
  83. ' SendMessage() is the message sending function of the Windows 3.x API.  
  84. Declare Function SendMessage Lib "USER" (ByVal hWnd As Integer, ByVal 
  85. wMsg As Integer, ByVal wParm As Integer, ByVal lParam As Any) As Long
  86.  
  87. Sub PayButton_Click ()
  88.     Amount! = Val(DollarCtrl.text) + Val(CentCtrl.text) / 100
  89.     balance = balance - Amount!
  90.     If balance < 0 Then                    
  91.          Beep                               ' warn user if insufficient funds
  92.          MsgBox "Insufficient Funds - Check Cancelled", 0, "ERROR!"
  93.          balance = balance + Amount!
  94.     Else
  95.          check.NumField = CheckNumLabel.Caption    ' store last check, remarks
  96.          check.RemarksField = RemarksCtrl.text     ' and store ink field
  97.          check.SignatureField = DuplicatePenData(SignatureCtrl.hInk, ByVal 0)
  98.  
  99.     PayToCtrl.text = ""                           ' initialize input fields
  100.  
  101.     PayButton.Enabled = False
  102. End Sub
  103.  
  104. Sub ShowLastCmd_Click ()         ' "Show Last" command function
  105.         
  106.      lParam = check.SignatureField           ' Force integer into long
  107.      CheckNumLabel.Caption = check.NumField  ' restore last check and
  108.                                              ' retrieve ink from memory
  109.      lRet = SendMessage(SignatureCtrl.hWnd, WM_HEDITCTL, HE_SETINKMODE, lParam)
  110. End Sub
  111.  
  112.  
  113.